﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace Aribaccio.Device
{
    /// <summary>
    /// 设备连接参数
    /// </summary>
    public class DevicePara : IDevicePara
    {
        /// <summary>
        /// 设备名称
        /// </summary>
        public string DeviceName { get; set; }
        /// <summary>
        /// 设备描述
        /// </summary>
        public string DeviceCaption { get; set; }
        /// <summary>
        /// 设备类型名称
        /// </summary>
        public string DeviceType { get; set; }
        /// <summary>
        /// 设备模组类型
        /// </summary>
        public DeviceModule ModuleType { get; set; }
        /// <summary>
        /// 设备连接类型
        /// </summary>
        public DeviceConnectType ConnectType { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public DevicePara()
        {
            this.DeviceName = string.Empty;
            this.DeviceCaption = string.Empty;
            this.DeviceType = "None";
            this.ModuleType = DeviceModule.None;
            this.ConnectType = DeviceConnectType.None;
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="argConnectType">设备连接类型</param>
        public DevicePara(DeviceConnectType argConnectType)
            : this()
        {
            this.ConnectType = argConnectType;
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="argDeviceName">数据设备名称</param>
        /// <param name="argDeviceCaption">数据设备描述</param>
        public DevicePara(string argDeviceName, string argDeviceCaption)
            : this()
        {
            this.DeviceName = argDeviceName;
            this.DeviceCaption = argDeviceCaption;
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="argDeviceName">数据设备名称</param>
        /// <param name="argDeviceCaption">数据设备描述</param>
        /// <param name="argDeviceType">设备类型</param>
        /// <param name="argConnectType">设备连接类型</param>
        public DevicePara(string argDeviceName, string argDeviceCaption, string argDeviceType, DeviceConnectType argConnectType)
            : this(argDeviceName, argDeviceCaption)
        {
            this.DeviceType = argDeviceType;
            this.ConnectType = argConnectType;
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="argDeviceName">数据设备名称</param>
        /// <param name="argDeviceCaption">数据设备描述</param>
        /// <param name="argDeviceType">设备类型</param>
        /// <param name="argModuleType">设备模组类型</param>
        public DevicePara(string argDeviceName, string argDeviceCaption, string argDeviceType, DeviceConnectType argConnectType, DeviceModule argModuleType)
            : this(argDeviceName, argDeviceCaption)
        {
            this.DeviceType = argDeviceType;
            this.ModuleType = argModuleType;
            this.ConnectType = argConnectType;
        }

        /// <summary>
        /// 浅复制(浅克隆)
        /// </summary>
        /// <returns></returns>
        public virtual IDevicePara Clone()
        {
            return (IDevicePara)this.MemberwiseClone();
        }

        /// <summary>
        /// 深复制(深度克隆)
        /// </summary>
        /// <returns></returns>
        public virtual IDevicePara CloneDeep()
        {
            return new DevicePara()
            {
                DeviceName = this.DeviceName,
                DeviceCaption = this.DeviceCaption,
                DeviceType = this.DeviceType,
                ModuleType = this.ModuleType
            };
            //try
            //{
            //    using (MemoryStream memStream = new MemoryStream())
            //    {
            //        BinaryFormatter binaryFormatter = new BinaryFormatter();
            //        binaryFormatter.Serialize(memStream, this);
            //        memStream.Seek(0, SeekOrigin.Begin);
            //        return (IDevicePara)binaryFormatter.Deserialize(memStream);
            //    }
            //}
            //catch (Exception)
            //{
            //    return default(IDevicePara);
            //}
        }
    }
}
